{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "machine_shape": "hm",
      "gpuType": "V100",
      "authorship_tag": "ABX9TyPyrn6jFZi/oEnzl09PL+i6",
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/KevinWang676/Bark-Voice-Cloning/blob/main/Bark_Coqui.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "dqFwQ3acv7EJ",
        "outputId": "d7a428a4-dee8-4c9a-81c8-c36bf1211edc"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Cloning into 'Bark-Coqui'...\n",
            "remote: Enumerating objects: 78, done.\u001b[K\n",
            "remote: Counting objects: 100% (78/78), done.\u001b[K\n",
            "remote: Compressing objects: 100% (60/60), done.\u001b[K\n",
            "remote: Total 78 (delta 22), reused 54 (delta 14), pack-reused 0\u001b[K\n",
            "Unpacking objects: 100% (78/78), 3.04 MiB | 7.62 MiB/s, done.\n"
          ]
        }
      ],
      "source": [
        "!git clone https://huggingface.co/spaces/kevinwang676/Bark-Coqui"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "cd Bark-Coqui"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "rlBjfzJkwDV9",
        "outputId": "a141e56b-0200-4526-8356-49dcb35d2c7b"
      },
      "execution_count": 2,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/Bark-Coqui\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "pip install -r requirements.txt"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "id": "8bvGc1l5DgFm",
        "outputId": "3332cd5b-47ae-458b-dca3-5001234a8f8c"
      },
      "execution_count": 4,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "Requirement already satisfied: TTS==0.17.8 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 1)) (0.17.8)\n",
            "Requirement already satisfied: transformers in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 2)) (4.33.3)\n",
            "Requirement already satisfied: scipy==1.11.3 in /usr/local/lib/python3.10/dist-packages (from -r requirements.txt (line 3)) (1.11.3)\n",
            "Collecting pydub==0.25.1 (from -r requirements.txt (line 4))\n",
            "  Downloading pydub-0.25.1-py2.py3-none-any.whl (32 kB)\n",
            "Collecting diffq==0.2.4 (from -r requirements.txt (line 5))\n",
            "  Downloading diffq-0.2.4-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (418 kB)\n",
            "\u001b[2K     \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m418.8/418.8 kB\u001b[0m \u001b[31m8.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
            "\u001b[?25hRequirement already satisfied: cython==0.29.30 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.29.30)\n",
            "Requirement already satisfied: torch>=1.7 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (2.0.1+cu118)\n",
            "Requirement already satisfied: torchaudio in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (2.0.2+cu118)\n",
            "Requirement already satisfied: soundfile==0.12.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.12.1)\n",
            "Requirement already satisfied: librosa==0.10.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.10.0)\n",
            "Requirement already satisfied: scikit-learn==1.3.0 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (1.3.0)\n",
            "Requirement already satisfied: inflect==5.6.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (5.6.2)\n",
            "Requirement already satisfied: tqdm==4.64.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (4.64.1)\n",
            "Requirement already satisfied: anyascii==0.3.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.3.2)\n",
            "Requirement already satisfied: pyyaml==6.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (6.0.1)\n",
            "Requirement already satisfied: fsspec==2023.6.0 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (2023.6.0)\n",
            "Requirement already satisfied: aiohttp==3.8.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (3.8.6)\n",
            "Requirement already satisfied: packaging==23.1 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (23.1)\n",
            "Requirement already satisfied: flask==2.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (2.2.5)\n",
            "Requirement already satisfied: pysbd==0.3.4 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.3.4)\n",
            "Requirement already satisfied: umap-learn==0.5.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.5.4)\n",
            "Requirement already satisfied: pandas<2.0,>=1.4 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (1.5.3)\n",
            "Requirement already satisfied: matplotlib==3.7.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (3.7.1)\n",
            "Requirement already satisfied: trainer in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.0.31)\n",
            "Requirement already satisfied: coqpit>=0.0.16 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.0.17)\n",
            "Requirement already satisfied: jieba in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.42.1)\n",
            "Requirement already satisfied: pypinyin in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.49.0)\n",
            "Requirement already satisfied: gruut[de,es,fr]==2.2.3 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (2.2.3)\n",
            "Requirement already satisfied: jamo in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.4.1)\n",
            "Requirement already satisfied: nltk in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (3.8.1)\n",
            "Requirement already satisfied: g2pkk>=0.1.1 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.1.2)\n",
            "Requirement already satisfied: bangla in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.0.2)\n",
            "Requirement already satisfied: bnnumerizer in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.0.2)\n",
            "Requirement already satisfied: bnunicodenormalizer in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.1.6)\n",
            "Requirement already satisfied: k-diffusion in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.0.16)\n",
            "Requirement already satisfied: einops==0.6.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.6.1)\n",
            "Requirement already satisfied: encodec==0.1.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.1.1)\n",
            "Requirement already satisfied: unidecode==1.3.* in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (1.3.7)\n",
            "Requirement already satisfied: numpy==1.22.0 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (1.22.0)\n",
            "Requirement already satisfied: numba==0.57.0 in /usr/local/lib/python3.10/dist-packages (from TTS==0.17.8->-r requirements.txt (line 1)) (0.57.0)\n",
            "Requirement already satisfied: filelock in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 2)) (3.12.4)\n",
            "Requirement already satisfied: huggingface-hub<1.0,>=0.15.1 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 2)) (0.18.0)\n",
            "Requirement already satisfied: regex!=2019.12.17 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 2)) (2023.6.3)\n",
            "Requirement already satisfied: requests in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 2)) (2.31.0)\n",
            "Requirement already satisfied: tokenizers!=0.11.3,<0.14,>=0.11.1 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 2)) (0.13.3)\n",
            "Requirement already satisfied: safetensors>=0.3.1 in /usr/local/lib/python3.10/dist-packages (from transformers->-r requirements.txt (line 2)) (0.4.0)\n",
            "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (23.1.0)\n",
            "Requirement already satisfied: charset-normalizer<4.0,>=2.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (3.3.0)\n",
            "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (6.0.4)\n",
            "Requirement already satisfied: async-timeout<5.0,>=4.0.0a3 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (4.0.3)\n",
            "Requirement already satisfied: yarl<2.0,>=1.0 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.9.2)\n",
            "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.4.0)\n",
            "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.10/dist-packages (from aiohttp==3.8.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.3.1)\n",
            "Requirement already satisfied: Werkzeug>=2.2.2 in /usr/local/lib/python3.10/dist-packages (from flask==2.*->TTS==0.17.8->-r requirements.txt (line 1)) (3.0.0)\n",
            "Requirement already satisfied: Jinja2>=3.0 in /usr/local/lib/python3.10/dist-packages (from flask==2.*->TTS==0.17.8->-r requirements.txt (line 1)) (3.1.2)\n",
            "Requirement already satisfied: itsdangerous>=2.0 in /usr/local/lib/python3.10/dist-packages (from flask==2.*->TTS==0.17.8->-r requirements.txt (line 1)) (2.1.2)\n",
            "Requirement already satisfied: click>=8.0 in /usr/local/lib/python3.10/dist-packages (from flask==2.*->TTS==0.17.8->-r requirements.txt (line 1)) (8.1.7)\n",
            "Requirement already satisfied: Babel<3.0.0,>=2.8.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (2.13.0)\n",
            "Requirement already satisfied: dateparser~=1.1.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (1.1.8)\n",
            "Requirement already satisfied: gruut-ipa<1.0,>=0.12.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (0.13.0)\n",
            "Requirement already satisfied: gruut-lang-en~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (2.0.0)\n",
            "Requirement already satisfied: jsonlines~=1.2.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (1.2.0)\n",
            "Requirement already satisfied: networkx<3.0.0,>=2.5.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (2.8.8)\n",
            "Requirement already satisfied: num2words<1.0.0,>=0.5.10 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (0.5.13)\n",
            "Requirement already satisfied: python-crfsuite~=0.9.7 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (0.9.9)\n",
            "Requirement already satisfied: gruut-lang-es~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (2.0.0)\n",
            "Requirement already satisfied: gruut-lang-de~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (2.0.0)\n",
            "Requirement already satisfied: gruut-lang-fr~=2.0.0 in /usr/local/lib/python3.10/dist-packages (from gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (2.0.2)\n",
            "Requirement already satisfied: audioread>=2.1.9 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (3.0.1)\n",
            "Requirement already satisfied: joblib>=0.14 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.3.2)\n",
            "Requirement already satisfied: decorator>=4.3.0 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (4.4.2)\n",
            "Requirement already satisfied: pooch>=1.0 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.7.0)\n",
            "Requirement already satisfied: soxr>=0.3.2 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (0.3.7)\n",
            "Requirement already satisfied: typing-extensions>=4.1.1 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (4.5.0)\n",
            "Requirement already satisfied: lazy-loader>=0.1 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (0.3)\n",
            "Requirement already satisfied: msgpack>=1.0 in /usr/local/lib/python3.10/dist-packages (from librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.0.7)\n",
            "Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.1.1)\n",
            "Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (0.12.1)\n",
            "Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (4.43.1)\n",
            "Requirement already satisfied: kiwisolver>=1.0.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.4.5)\n",
            "Requirement already satisfied: pillow>=6.2.0 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (9.4.0)\n",
            "Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (3.1.1)\n",
            "Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.10/dist-packages (from matplotlib==3.7.*->TTS==0.17.8->-r requirements.txt (line 1)) (2.8.2)\n",
            "Requirement already satisfied: llvmlite<0.41,>=0.40.0dev0 in /usr/local/lib/python3.10/dist-packages (from numba==0.57.0->TTS==0.17.8->-r requirements.txt (line 1)) (0.40.1)\n",
            "Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from scikit-learn==1.3.0->TTS==0.17.8->-r requirements.txt (line 1)) (3.2.0)\n",
            "Requirement already satisfied: cffi>=1.0 in /usr/local/lib/python3.10/dist-packages (from soundfile==0.12.*->TTS==0.17.8->-r requirements.txt (line 1)) (1.16.0)\n",
            "Requirement already satisfied: pynndescent>=0.5 in /usr/local/lib/python3.10/dist-packages (from umap-learn==0.5.*->TTS==0.17.8->-r requirements.txt (line 1)) (0.5.10)\n",
            "Requirement already satisfied: tbb>=2019.0 in /usr/local/lib/python3.10/dist-packages (from umap-learn==0.5.*->TTS==0.17.8->-r requirements.txt (line 1)) (2021.10.0)\n",
            "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.10/dist-packages (from pandas<2.0,>=1.4->TTS==0.17.8->-r requirements.txt (line 1)) (2023.3.post1)\n",
            "Requirement already satisfied: sympy in /usr/local/lib/python3.10/dist-packages (from torch>=1.7->TTS==0.17.8->-r requirements.txt (line 1)) (1.12)\n",
            "Requirement already satisfied: triton==2.0.0 in /usr/local/lib/python3.10/dist-packages (from torch>=1.7->TTS==0.17.8->-r requirements.txt (line 1)) (2.0.0)\n",
            "Requirement already satisfied: cmake in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch>=1.7->TTS==0.17.8->-r requirements.txt (line 1)) (3.27.7)\n",
            "Requirement already satisfied: lit in /usr/local/lib/python3.10/dist-packages (from triton==2.0.0->torch>=1.7->TTS==0.17.8->-r requirements.txt (line 1)) (17.0.2)\n",
            "Requirement already satisfied: accelerate in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.23.0)\n",
            "Requirement already satisfied: clean-fid in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.1.35)\n",
            "Requirement already satisfied: clip-anytorch in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (2.5.2)\n",
            "Requirement already satisfied: jsonmerge in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (1.9.2)\n",
            "Requirement already satisfied: kornia in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.7.0)\n",
            "Requirement already satisfied: resize-right in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.0.2)\n",
            "Requirement already satisfied: scikit-image in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.19.3)\n",
            "Requirement already satisfied: torchdiffeq in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.2.3)\n",
            "Requirement already satisfied: torchsde in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.2.6)\n",
            "Requirement already satisfied: torchvision in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.15.2+cu118)\n",
            "Requirement already satisfied: wandb in /usr/local/lib/python3.10/dist-packages (from k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.15.12)\n",
            "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->-r requirements.txt (line 2)) (3.4)\n",
            "Requirement already satisfied: urllib3<3,>=1.21.1 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->-r requirements.txt (line 2)) (2.0.6)\n",
            "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.10/dist-packages (from requests->transformers->-r requirements.txt (line 2)) (2023.7.22)\n",
            "Requirement already satisfied: psutil in /usr/local/lib/python3.10/dist-packages (from trainer->TTS==0.17.8->-r requirements.txt (line 1)) (5.9.5)\n",
            "Requirement already satisfied: tensorboard in /usr/local/lib/python3.10/dist-packages (from trainer->TTS==0.17.8->-r requirements.txt (line 1)) (2.13.0)\n",
            "Requirement already satisfied: pycparser in /usr/local/lib/python3.10/dist-packages (from cffi>=1.0->soundfile==0.12.*->TTS==0.17.8->-r requirements.txt (line 1)) (2.21)\n",
            "Requirement already satisfied: tzlocal in /usr/local/lib/python3.10/dist-packages (from dateparser~=1.1.0->gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (5.1)\n",
            "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.10/dist-packages (from Jinja2>=3.0->flask==2.*->TTS==0.17.8->-r requirements.txt (line 1)) (2.1.3)\n",
            "Requirement already satisfied: six in /usr/local/lib/python3.10/dist-packages (from jsonlines~=1.2.0->gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (1.16.0)\n",
            "Requirement already satisfied: docopt>=0.6.2 in /usr/local/lib/python3.10/dist-packages (from num2words<1.0.0,>=0.5.10->gruut[de,es,fr]==2.2.3->TTS==0.17.8->-r requirements.txt (line 1)) (0.6.2)\n",
            "Requirement already satisfied: platformdirs>=2.5.0 in /usr/local/lib/python3.10/dist-packages (from pooch>=1.0->librosa==0.10.*->TTS==0.17.8->-r requirements.txt (line 1)) (3.11.0)\n",
            "Requirement already satisfied: ftfy in /usr/local/lib/python3.10/dist-packages (from clip-anytorch->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (6.1.1)\n",
            "Requirement already satisfied: jsonschema>2.4.0 in /usr/local/lib/python3.10/dist-packages (from jsonmerge->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (4.19.1)\n",
            "Requirement already satisfied: imageio>=2.4.1 in /usr/local/lib/python3.10/dist-packages (from scikit-image->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (2.31.5)\n",
            "Requirement already satisfied: tifffile>=2019.7.26 in /usr/local/lib/python3.10/dist-packages (from scikit-image->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (2023.9.26)\n",
            "Requirement already satisfied: PyWavelets>=1.1.1 in /usr/local/lib/python3.10/dist-packages (from scikit-image->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (1.4.1)\n",
            "Requirement already satisfied: mpmath>=0.19 in /usr/local/lib/python3.10/dist-packages (from sympy->torch>=1.7->TTS==0.17.8->-r requirements.txt (line 1)) (1.3.0)\n",
            "Requirement already satisfied: absl-py>=0.4 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (1.4.0)\n",
            "Requirement already satisfied: grpcio>=1.48.2 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (1.59.0)\n",
            "Requirement already satisfied: google-auth<3,>=1.6.3 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (2.17.3)\n",
            "Requirement already satisfied: google-auth-oauthlib<1.1,>=0.5 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (1.0.0)\n",
            "Requirement already satisfied: markdown>=2.6.8 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (3.5)\n",
            "Requirement already satisfied: protobuf>=3.19.6 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (3.20.3)\n",
            "Requirement already satisfied: setuptools>=41.0.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (67.7.2)\n",
            "Requirement already satisfied: tensorboard-data-server<0.8.0,>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (0.7.1)\n",
            "Requirement already satisfied: wheel>=0.26 in /usr/local/lib/python3.10/dist-packages (from tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (0.41.2)\n",
            "Requirement already satisfied: trampoline>=0.1.2 in /usr/local/lib/python3.10/dist-packages (from torchsde->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.1.2)\n",
            "Requirement already satisfied: GitPython!=3.1.29,>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (3.1.40)\n",
            "Requirement already satisfied: sentry-sdk>=1.0.0 in /usr/local/lib/python3.10/dist-packages (from wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (1.32.0)\n",
            "Requirement already satisfied: docker-pycreds>=0.4.0 in /usr/local/lib/python3.10/dist-packages (from wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.4.0)\n",
            "Requirement already satisfied: pathtools in /usr/local/lib/python3.10/dist-packages (from wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.1.2)\n",
            "Requirement already satisfied: setproctitle in /usr/local/lib/python3.10/dist-packages (from wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (1.3.3)\n",
            "Requirement already satisfied: appdirs>=1.4.3 in /usr/local/lib/python3.10/dist-packages (from wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (1.4.4)\n",
            "Requirement already satisfied: gitdb<5,>=4.0.1 in /usr/local/lib/python3.10/dist-packages (from GitPython!=3.1.29,>=1.0.0->wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (4.0.10)\n",
            "Requirement already satisfied: cachetools<6.0,>=2.0.0 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (5.3.1)\n",
            "Requirement already satisfied: pyasn1-modules>=0.2.1 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (0.3.0)\n",
            "Requirement already satisfied: rsa<5,>=3.1.4 in /usr/local/lib/python3.10/dist-packages (from google-auth<3,>=1.6.3->tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (4.9)\n",
            "Requirement already satisfied: requests-oauthlib>=0.7.0 in /usr/local/lib/python3.10/dist-packages (from google-auth-oauthlib<1.1,>=0.5->tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (1.3.1)\n",
            "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in /usr/local/lib/python3.10/dist-packages (from jsonschema>2.4.0->jsonmerge->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (2023.7.1)\n",
            "Requirement already satisfied: referencing>=0.28.4 in /usr/local/lib/python3.10/dist-packages (from jsonschema>2.4.0->jsonmerge->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.30.2)\n",
            "Requirement already satisfied: rpds-py>=0.7.1 in /usr/local/lib/python3.10/dist-packages (from jsonschema>2.4.0->jsonmerge->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.10.6)\n",
            "Requirement already satisfied: wcwidth>=0.2.5 in /usr/local/lib/python3.10/dist-packages (from ftfy->clip-anytorch->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (0.2.8)\n",
            "Requirement already satisfied: smmap<6,>=3.0.1 in /usr/local/lib/python3.10/dist-packages (from gitdb<5,>=4.0.1->GitPython!=3.1.29,>=1.0.0->wandb->k-diffusion->TTS==0.17.8->-r requirements.txt (line 1)) (5.0.1)\n",
            "Requirement already satisfied: pyasn1<0.6.0,>=0.4.6 in /usr/local/lib/python3.10/dist-packages (from pyasn1-modules>=0.2.1->google-auth<3,>=1.6.3->tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (0.5.0)\n",
            "Requirement already satisfied: oauthlib>=3.0.0 in /usr/local/lib/python3.10/dist-packages (from requests-oauthlib>=0.7.0->google-auth-oauthlib<1.1,>=0.5->tensorboard->trainer->TTS==0.17.8->-r requirements.txt (line 1)) (3.2.2)\n",
            "Installing collected packages: pydub, diffq\n",
            "Successfully installed diffq-0.2.4 pydub-0.25.1\n"
          ]
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "import gradio as gr\n",
        "from share_btn import community_icon_html, loading_icon_html, share_js\n",
        "import os\n",
        "import shutil\n",
        "\n",
        "#from huggingface_hub import snapshot_download\n",
        "import numpy as np\n",
        "from scipy.io import wavfile\n",
        "from scipy.io.wavfile import write, read\n",
        "from pydub import AudioSegment\n",
        "\n",
        "file_upload_available = os.environ.get(\"ALLOW_FILE_UPLOAD\")\n",
        "\n",
        "import json\n",
        "with open(\"characters.json\", \"r\") as file:\n",
        "    data = json.load(file)\n",
        "    characters = [\n",
        "        {\n",
        "            \"image\": item[\"image\"],\n",
        "            \"title\": item[\"title\"],\n",
        "            \"speaker\": item[\"speaker\"]\n",
        "        }\n",
        "        for item in data\n",
        "    ]\n",
        "\n",
        "from TTS.api import TTS\n",
        "tts = TTS(\"tts_models/multilingual/multi-dataset/bark\", gpu=True)\n",
        "\n",
        "def cut_wav(input_path, max_duration):\n",
        "    # Load the WAV file\n",
        "    audio = AudioSegment.from_wav(input_path)\n",
        "\n",
        "    # Calculate the duration of the audio\n",
        "    audio_duration = len(audio) / 1000  # Convert milliseconds to seconds\n",
        "\n",
        "    # Determine the duration to cut (maximum of max_duration and actual audio duration)\n",
        "    cut_duration = min(max_duration, audio_duration)\n",
        "\n",
        "    # Cut the audio\n",
        "    cut_audio = audio[:int(cut_duration * 1000)]  # Convert seconds to milliseconds\n",
        "\n",
        "    # Get the input file name without extension\n",
        "    file_name = os.path.splitext(os.path.basename(input_path))[0]\n",
        "\n",
        "    # Construct the output file path with the original file name and \"_cut\" suffix\n",
        "    output_path = f\"{file_name}_cut.wav\"\n",
        "\n",
        "    # Save the cut audio as a new WAV file\n",
        "    cut_audio.export(output_path, format=\"wav\")\n",
        "\n",
        "    return output_path\n",
        "\n",
        "def load_hidden(audio_in):\n",
        "    return audio_in\n",
        "\n",
        "def load_hidden_mic(audio_in):\n",
        "    print(\"MICRO IN HAS CHANGED\")\n",
        "\n",
        "    library_path = 'bark_voices'\n",
        "    folder_name = 'audio-0-100'\n",
        "    second_folder_name = 'audio-0-100_cleaned'\n",
        "\n",
        "    folder_path = os.path.join(library_path, folder_name)\n",
        "    second_folder_path = os.path.join(library_path, second_folder_name)\n",
        "\n",
        "    if os.path.exists(folder_path):\n",
        "        try:\n",
        "            shutil.rmtree(folder_path)\n",
        "            print(f\"Successfully deleted the folder: {folder_path}\")\n",
        "        except OSError as e:\n",
        "            print(f\"Error: {folder_path} - {e.strerror}\")\n",
        "    else:\n",
        "        print(f\"The folder does not exist: {folder_path}\")\n",
        "\n",
        "    if os.path.exists(second_folder_path):\n",
        "        try:\n",
        "            shutil.rmtree(second_folder_path)\n",
        "            print(f\"Successfully deleted the folder: {second_folder_path}\")\n",
        "        except OSError as e:\n",
        "            print(f\"Error: {second_folder_path} - {e.strerror}\")\n",
        "    else:\n",
        "        print(f\"The folder does not exist: {second_folder_path}\")\n",
        "\n",
        "    return audio_in\n",
        "\n",
        "def clear_clean_ckeck():\n",
        "    return False\n",
        "\n",
        "def wipe_npz_file(folder_path):\n",
        "    if os.path.exists(folder_path):\n",
        "        #shutil.rmtree(folder_path)\n",
        "        print(folder_path)\n",
        "    else :\n",
        "        print(\"path does not exists yet\")\n",
        "    print(\"YO\")\n",
        "\n",
        "def split_process(audio, chosen_out_track):\n",
        "    os.makedirs(\"out\", exist_ok=True)\n",
        "    write('test.wav', audio[0], audio[1])\n",
        "    os.system(\"python3 -m demucs.separate -n mdx_extra_q -j 4 test.wav -o out\")\n",
        "    #return \"./out/mdx_extra_q/test/vocals.wav\",\"./out/mdx_extra_q/test/bass.wav\",\"./out/mdx_extra_q/test/drums.wav\",\"./out/mdx_extra_q/test/other.wav\"\n",
        "    if chosen_out_track == \"vocals\":\n",
        "        return \"./out/mdx_extra_q/test/vocals.wav\"\n",
        "    elif chosen_out_track == \"bass\":\n",
        "        return \"./out/mdx_extra_q/test/bass.wav\"\n",
        "    elif chosen_out_track == \"drums\":\n",
        "        return \"./out/mdx_extra_q/test/drums.wav\"\n",
        "    elif chosen_out_track == \"other\":\n",
        "        return \"./out/mdx_extra_q/test/other.wav\"\n",
        "    elif chosen_out_track == \"all-in\":\n",
        "        return \"test.wav\"\n",
        "\n",
        "def update_selection(selected_state: gr.SelectData):\n",
        "    c_image = characters[selected_state.index][\"image\"]\n",
        "    c_title = characters[selected_state.index][\"title\"]\n",
        "    c_speaker = characters[selected_state.index][\"speaker\"]\n",
        "\n",
        "    return c_title, selected_state\n",
        "\n",
        "\n",
        "def infer(prompt, input_wav_file, clean_audio, hidden_numpy_audio):\n",
        "\n",
        "    if clean_audio is True :\n",
        "        # Extract the file name without the extension\n",
        "        new_name = os.path.splitext(os.path.basename(input_wav_file))[0]\n",
        "        check_name = os.path.join(\"bark_voices\", f\"{new_name}_cleaned\")\n",
        "        if os.path.exists(check_name):\n",
        "            source_path = os.path.join(check_name, f\"{new_name}_cleaned.wav\")\n",
        "        else:\n",
        "            source_path = split_process(hidden_numpy_audio, \"vocals\")\n",
        "\n",
        "            # Rename the file\n",
        "            new_path = os.path.join(os.path.dirname(source_path), f\"{new_name}_cleaned.wav\")\n",
        "            os.rename(source_path, new_path)\n",
        "            source_path = new_path\n",
        "    else :\n",
        "        # Path to your WAV file\n",
        "        source_path = input_wav_file\n",
        "\n",
        "    # Destination directory\n",
        "    destination_directory = \"bark_voices\"\n",
        "\n",
        "    # Extract the file name without the extension\n",
        "    file_name = os.path.splitext(os.path.basename(source_path))[0]\n",
        "\n",
        "    # Construct the full destination directory path\n",
        "    destination_path = os.path.join(destination_directory, file_name)\n",
        "\n",
        "    # Create the new directory\n",
        "    os.makedirs(destination_path, exist_ok=True)\n",
        "\n",
        "    # Move the WAV file to the new directory\n",
        "    shutil.move(source_path, os.path.join(destination_path, f\"{file_name}.wav\"))\n",
        "\n",
        "    tts.tts_to_file(text=prompt,\n",
        "                file_path=\"output.wav\",\n",
        "                voice_dir=\"bark_voices/\",\n",
        "                speaker=f\"{file_name}\")\n",
        "\n",
        "    # List all the files and subdirectories in the given directory\n",
        "    contents = os.listdir(f\"bark_voices/{file_name}\")\n",
        "\n",
        "    # Print the contents\n",
        "    for item in contents:\n",
        "        print(item)\n",
        "\n",
        "    tts_video = gr.make_waveform(audio=\"output.wav\")\n",
        "\n",
        "    return \"output.wav\", tts_video, gr.update(value=f\"bark_voices/{file_name}/{contents[1]}\", visible=True), gr.Group.update(visible=True), destination_path\n",
        "\n",
        "def infer_from_c(prompt, c_name):\n",
        "\n",
        "    tts.tts_to_file(text=prompt,\n",
        "                file_path=\"output.wav\",\n",
        "                voice_dir=\"examples/library/\",\n",
        "                speaker=f\"{c_name}\")\n",
        "\n",
        "    tts_video = gr.make_waveform(audio=\"output.wav\")\n",
        "\n",
        "    return \"output.wav\", tts_video, gr.update(value=f\"examples/library/{c_name}/{c_name}.npz\", visible=True), gr.Group.update(visible=True)\n",
        "\n",
        "\n",
        "css = \"\"\"\n",
        "#col-container {max-width: 780px; margin-left: auto; margin-right: auto;}\n",
        "a {text-decoration-line: underline; font-weight: 600;}\n",
        ".mic-wrap > button {\n",
        "    width: 100%;\n",
        "    height: 60px;\n",
        "    font-size: 1.4em!important;\n",
        "}\n",
        ".record-icon.svelte-1thnwz {\n",
        "    display: flex;\n",
        "    position: relative;\n",
        "    margin-right: var(--size-2);\n",
        "    width: unset;\n",
        "    height: unset;\n",
        "}\n",
        "span.record-icon > span.dot.svelte-1thnwz {\n",
        "    width: 20px!important;\n",
        "    height: 20px!important;\n",
        "}\n",
        ".animate-spin {\n",
        "  animation: spin 1s linear infinite;\n",
        "}\n",
        "@keyframes spin {\n",
        "  from {\n",
        "      transform: rotate(0deg);\n",
        "  }\n",
        "  to {\n",
        "      transform: rotate(360deg);\n",
        "  }\n",
        "}\n",
        "#share-btn-container {\n",
        "  display: flex;\n",
        "  padding-left: 0.5rem !important;\n",
        "  padding-right: 0.5rem !important;\n",
        "  background-color: #000000;\n",
        "  justify-content: center;\n",
        "  align-items: center;\n",
        "  border-radius: 9999px !important;\n",
        "  max-width: 15rem;\n",
        "  height: 36px;\n",
        "}\n",
        "div#share-btn-container > div {\n",
        "    flex-direction: row;\n",
        "    background: black;\n",
        "    align-items: center;\n",
        "}\n",
        "#share-btn-container:hover {\n",
        "  background-color: #060606;\n",
        "}\n",
        "#share-btn {\n",
        "  all: initial;\n",
        "  color: #ffffff;\n",
        "  font-weight: 600;\n",
        "  cursor:pointer;\n",
        "  font-family: 'IBM Plex Sans', sans-serif;\n",
        "  margin-left: 0.5rem !important;\n",
        "  padding-top: 0.5rem !important;\n",
        "  padding-bottom: 0.5rem !important;\n",
        "  right:0;\n",
        "}\n",
        "#share-btn * {\n",
        "  all: unset;\n",
        "}\n",
        "#share-btn-container div:nth-child(-n+2){\n",
        "  width: auto !important;\n",
        "  min-height: 0px !important;\n",
        "}\n",
        "#share-btn-container .wrap {\n",
        "  display: none !important;\n",
        "}\n",
        "#share-btn-container.hidden {\n",
        "  display: none!important;\n",
        "}\n",
        "img[src*='#center'] {\n",
        "    display: block;\n",
        "    margin: auto;\n",
        "}\n",
        ".footer {\n",
        "        margin-bottom: 45px;\n",
        "        margin-top: 10px;\n",
        "        text-align: center;\n",
        "        border-bottom: 1px solid #e5e5e5;\n",
        "    }\n",
        "    .footer>p {\n",
        "        font-size: .8rem;\n",
        "        display: inline-block;\n",
        "        padding: 0 10px;\n",
        "        transform: translateY(10px);\n",
        "        background: white;\n",
        "    }\n",
        "    .dark .footer {\n",
        "        border-color: #303030;\n",
        "    }\n",
        "    .dark .footer>p {\n",
        "        background: #0b0f19;\n",
        "    }\n",
        ".disclaimer {\n",
        "    text-align: left;\n",
        "}\n",
        ".disclaimer > p {\n",
        "    font-size: .8rem;\n",
        "}\n",
        "\"\"\"\n",
        "\n",
        "with gr.Blocks(css=css) as demo:\n",
        "    with gr.Column(elem_id=\"col-container\"):\n",
        "\n",
        "        gr.HTML(\"<center>\"\n",
        "                \"<h1>🌊💕🎶 Bark真实拟声全新升级：Bark+Coqui</h1>\"\n",
        "                \"</center>\")\n",
        "\n",
        "        gr.Markdown(\"### <center>🌟 开启声音情感真实复刻的新纪元<</center>\")\n",
        "\n",
        "        gr.Markdown(\"### <center>更多精彩应用，尽在[滔滔AI](http://www.talktalkai.com)；滔滔AI，为爱滔滔！💕</center>\")\n",
        "\n",
        "\n",
        "\n",
        "        with gr.Row():\n",
        "            with gr.Column():\n",
        "                prompt = gr.Textbox(\n",
        "                    label = \"请填写您想复刻的文本内容（英文）\",\n",
        "                    placeholder = \"Hello friend! How are you today?\",\n",
        "                    elem_id = \"tts-prompt\"\n",
        "                )\n",
        "\n",
        "                with gr.Tab(\"语音文件上传\"):\n",
        "\n",
        "                    with gr.Column():\n",
        "\n",
        "                        if file_upload_available == \"True\":\n",
        "                            audio_in = gr.Audio(\n",
        "                                label=\"请上传您想复刻的语音文件\",\n",
        "                                type=\"filepath\",\n",
        "                                source=\"upload\"\n",
        "                            )\n",
        "                        else:\n",
        "                            audio_in = gr.Audio(\n",
        "                                label=\"请上传您想复刻的语音文件\",\n",
        "                                type=\"filepath\",\n",
        "                                source=\"upload\"\n",
        "                            )\n",
        "                        clean_sample = gr.Checkbox(label=\"是否要对语音文件降噪\", value=False, visible=False)\n",
        "                        hidden_audio_numpy = gr.Audio(type=\"numpy\", visible=False)\n",
        "                        submit_btn = gr.Button(\"开启声音复刻之旅吧\", variant=\"primary\")\n",
        "\n",
        "                with gr.Tab(\"麦克风上传\"):\n",
        "                    texts_samples = gr.Textbox(label = \"Helpers\",\n",
        "                                               info = \"You can read out loud one of these sentences if you do not know what to record :)\",\n",
        "                                               value = \"\"\"\"Jazz, a quirky mix of groovy saxophones and wailing trumpets, echoes through the vibrant city streets.\"\n",
        "———\n",
        "\"A majestic orchestra plays enchanting melodies, filling the air with harmony.\"\n",
        "———\n",
        "\"The exquisite aroma of freshly baked bread wafts from a cozy bakery, enticing passersby.\"\n",
        "———\n",
        "\"A thunderous roar shakes the ground as a massive jet takes off into the sky, leaving trails of white behind.\"\n",
        "———\n",
        "\"Laughter erupts from a park where children play, their innocent voices rising like tinkling bells.\"\n",
        "———\n",
        "\"Waves crash on the beach, and seagulls caw as they soar overhead, a symphony of nature's sounds.\"\n",
        "———\n",
        "\"In the distance, a blacksmith hammers red-hot metal, the rhythmic clang punctuating the day.\"\n",
        "———\n",
        "\"As evening falls, a soft hush blankets the world, crickets chirping in a soothing rhythm.\"\n",
        "                                               \"\"\",\n",
        "                                               lines = 5,\n",
        "                                               visible = False\n",
        "                                              )\n",
        "                    micro_in = gr.Audio(\n",
        "                                label=\"请录制您的声音\",\n",
        "                                type=\"filepath\",\n",
        "                                source=\"microphone\",\n",
        "                                interactive = True\n",
        "                            )\n",
        "                    clean_micro = gr.Checkbox(label=\"是否要对语音文件降噪\", value=False, visible=False)\n",
        "                    micro_submit_btn = gr.Button(\"开启声音复刻之旅吧\", variant=\"primary\")\n",
        "\n",
        "                audio_in.upload(fn=load_hidden, inputs=[audio_in], outputs=[hidden_audio_numpy], queue=False)\n",
        "                micro_in.stop_recording(fn=load_hidden_mic, inputs=[micro_in], outputs=[hidden_audio_numpy], queue=False)\n",
        "\n",
        "\n",
        "                with gr.Tab(\"内置语音包\"):\n",
        "                    selected_state = gr.State()\n",
        "                    gallery_in = gr.Gallery(\n",
        "                                label=\"语音包预览\",\n",
        "                                value=[(item[\"image\"], item[\"title\"]) for item in characters],\n",
        "                                interactive = True,\n",
        "                                allow_preview=False,\n",
        "                                columns=3,\n",
        "                                elem_id=\"gallery\",\n",
        "                                show_share_button=False\n",
        "                            )\n",
        "                    c_submit_btn = gr.Button(\"开启声音复刻之旅吧\", variant=\"primary\")\n",
        "\n",
        "\n",
        "            with gr.Column():\n",
        "\n",
        "                cloned_out = gr.Audio(\n",
        "                    label=\"Text to speech output\",\n",
        "                    visible = False\n",
        "                )\n",
        "\n",
        "                video_out = gr.Video(\n",
        "                    label = \"为您合成的专属语音\",\n",
        "                    elem_id = \"voice-video-out\"\n",
        "                )\n",
        "\n",
        "                npz_file = gr.File(\n",
        "                    label = \".npz file\",\n",
        "                    visible = False\n",
        "                )\n",
        "\n",
        "                folder_path = gr.Textbox(visible=False)\n",
        "\n",
        "\n",
        "\n",
        "                character_name = gr.Textbox(\n",
        "                    label=\"角色名（选填）\",\n",
        "                    placeholder=\"您可以为语音说话人起个名字\",\n",
        "                    elem_id = \"character-name\",\n",
        "                    visible = False\n",
        "                )\n",
        "\n",
        "                voice_description = gr.Textbox(\n",
        "                    label=\"description\",\n",
        "                    placeholder=\"How would you describe that voice ? \",\n",
        "                    elem_id = \"voice-description\",\n",
        "                    visible = False\n",
        "                )\n",
        "\n",
        "\n",
        "        gallery_in.select(\n",
        "            update_selection,\n",
        "            outputs=[character_name, selected_state],\n",
        "            queue=False,\n",
        "            show_progress=False,\n",
        "        )\n",
        "\n",
        "        audio_in.change(fn=wipe_npz_file, inputs=[folder_path], queue=False)\n",
        "        micro_in.clear(fn=wipe_npz_file, inputs=[folder_path], queue=False)\n",
        "\n",
        "        gr.Examples(\n",
        "            examples = [\n",
        "                [\n",
        "                    \"Once upon a time, in a cozy little shell, lived a friendly crab named Crabby. Crabby loved his cozy home, but he always felt like something was missing.\",\n",
        "                    \"./examples/en_speaker_6.wav\",\n",
        "                    False,\n",
        "                    None\n",
        "                ],\n",
        "                [\n",
        "                    \"It was a typical afternoon in the bustling city, the sun shining brightly through the windows of the packed courtroom. Three people sat at the bar, their faces etched with worry and anxiety. \",\n",
        "                    \"./examples/en_speaker_9.wav\",\n",
        "                    False,\n",
        "                    None\n",
        "                ],\n",
        "            ],\n",
        "            fn = infer,\n",
        "            inputs = [\n",
        "                prompt,\n",
        "                audio_in,\n",
        "                clean_sample,\n",
        "                hidden_audio_numpy\n",
        "            ],\n",
        "            outputs = [\n",
        "                cloned_out,\n",
        "                video_out,\n",
        "                npz_file,\n",
        "                folder_path\n",
        "            ],\n",
        "            cache_examples = False\n",
        "        )\n",
        "\n",
        "\n",
        "\n",
        "    submit_btn.click(\n",
        "        fn = infer,\n",
        "        inputs = [\n",
        "            prompt,\n",
        "            audio_in,\n",
        "            clean_sample,\n",
        "            hidden_audio_numpy\n",
        "        ],\n",
        "        outputs = [\n",
        "            cloned_out,\n",
        "            video_out,\n",
        "            npz_file,\n",
        "            folder_path\n",
        "        ]\n",
        "    )\n",
        "\n",
        "    micro_submit_btn.click(\n",
        "        fn = infer,\n",
        "        inputs = [\n",
        "            prompt,\n",
        "            micro_in,\n",
        "            clean_micro,\n",
        "            hidden_audio_numpy\n",
        "        ],\n",
        "        outputs = [\n",
        "            cloned_out,\n",
        "            video_out,\n",
        "            npz_file,\n",
        "            folder_path\n",
        "        ]\n",
        "    )\n",
        "\n",
        "    c_submit_btn.click(\n",
        "        fn = infer_from_c,\n",
        "        inputs = [\n",
        "            prompt,\n",
        "            character_name\n",
        "        ],\n",
        "        outputs = [\n",
        "            cloned_out,\n",
        "            video_out,\n",
        "            npz_file\n",
        "        ]\n",
        "    )\n",
        "\n",
        "    gr.Markdown(\"### <center>注意❗：请不要生成会对个人以及组织造成侵害的内容，此程序仅供科研、学习及个人娱乐使用。</center>\")\n",
        "    gr.HTML('''\n",
        "        <div class=\"footer\">\n",
        "                    <p>🌊🏞️🎶 - 江水东流急，滔滔无尽声。 明·顾璘\n",
        "                    </p>\n",
        "        </div>\n",
        "    ''')\n",
        "\n",
        "\n",
        "demo.queue(api_open=False, max_size=10).launch(show_error=True, share=True)"
      ],
      "metadata": {
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 683
        },
        "id": "_ta7cT_bwON3",
        "outputId": "dd59e22d-d9c2-4add-e989-eda19158cdee"
      },
      "execution_count": 14,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stderr",
          "text": [
            "/usr/local/lib/python3.10/dist-packages/TTS/api.py:77: UserWarning: `gpu` will be deprecated. Please use `tts.to(device)` instead.\n",
            "  warnings.warn(\"`gpu` will be deprecated. Please use `tts.to(device)` instead.\")\n"
          ]
        },
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            " > tts_models/multilingual/multi-dataset/bark is already downloaded.\n",
            " > Using model: bark\n",
            "Colab notebook detected. To show errors in colab notebook, set debug=True in launch()\n",
            "Running on public URL: https://bace76d2c60ffb519d.gradio.live\n",
            "\n",
            "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
          ]
        },
        {
          "output_type": "display_data",
          "data": {
            "text/plain": [
              "<IPython.core.display.HTML object>"
            ],
            "text/html": [
              "<div><iframe src=\"https://bace76d2c60ffb519d.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
            ]
          },
          "metadata": {}
        },
        {
          "output_type": "execute_result",
          "data": {
            "text/plain": []
          },
          "metadata": {},
          "execution_count": 14
        }
      ]
    },
    {
      "cell_type": "code",
      "source": [],
      "metadata": {
        "id": "2JAmWXs_xW1M"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}